package com.flying.pas.form.service;

import com.flying.common.annotation.DaoCreate;
import com.flying.common.annotation.DaoQuery;
import com.flying.common.annotation.DaoRemove;
import com.flying.common.annotation.DaoUpdate;
import com.flying.common.util.Codes;
import com.flying.framework.annotation.MethodInfo;
import com.flying.framework.annotation.Param;
import com.flying.framework.annotation.Service;
import com.flying.framework.model.ActionResult;
import com.flying.framework.model.ModelFactory;
import com.flying.framework.model.QueryResult;
import com.flying.framework.service.AbstractService;
import com.flying.pas.form.model.Field;

@Service(value="FieldService", desc="字段")
public class FieldService extends AbstractService{
        
	@MethodInfo("新增")
	@DaoCreate(entity=Field.ENTITY_NAME)
	public Field create(
			@Param(value=Field.FORM_ID, required=true,	desc="表单ID") Long form_id,
			@Param(value=Field.TITLE, required=false,	desc="标题") String title,
			@Param(value=Field.NAME, required=true,	desc="字段名") String name,
			@Param(value=Field.DATA_TYPE, required=false,	desc="数据类型") String data_type,
			@Param(value=Field.DISPLAY_TYPE, required=false,	desc="显示类型") String display_type,
			
			@Param(value=Field.ORDER_INDEX, required=false,	desc="字段顺序") Integer order_index,
			@Param(value=Field.IS_COLUMN, required=false,	desc="网格列") Integer is_column,
			@Param(value=Field.IS_FIELD, required=false,	desc="表单字段") Integer is_field,
			@Param(value=Field.READONLY, required=false,	desc="是否只读") Integer readonly,
			@Param(value=Field.CONDITION, required=false,	desc="是否条件") Integer query_condition,
			
			@Param(value=Field.DS_MODULE_ID, required=false,	desc="配置代码") String ds_config_category,
			@Param(value=Field.DS_SERVICE_ID, required=false,	desc="数据源服务ID") String ds_service_id,
			@Param(value=Field.DS_QUERY, required=false,	desc="数据源查询条件") String ds_query,
			@Param(value=Field.DS_URL, required=false,	desc="数据源URL") String ds_url,
			@Param(value=Field.TEXT_FIELD, required=false,	desc="显示字段") String text_field,
			@Param(value=Field.VALUE_FIELD, required=false,	desc="值字段") String value_field,
			
			@Param(value=Field.IS_REQUIRED, required=false,	desc="是否必需") Integer is_required,
			@Param(value=Field.MAX_LENGTH, required=false,	desc="最大长度") Integer max_length,
			@Param(value=Field.MIN_VALUE, required=false,	desc="最小值") String min_value,
			@Param(value=Field.MAX_VALUE, required=false,	desc="最大值") String max_value,
			@Param(value=Field.DATA_FORMAT, required=false,	desc="数据格式") String data_format,
			
			@Param(value=Field.REMARKS, required=false,	desc="说明") String remarks,
			@Param(value=Field.STYLE, required=false,	desc="显示样式") String style
		
		) throws Exception {
		return ModelFactory.create(Field.class, 
				Field.IS_COLUMN, is_column == null?1: is_column, 
				Field.IS_FIELD, is_field == null?1: is_field, 
				Field.READONLY, readonly == null?0: readonly
			);
	}

	@MethodInfo("修改")
	@DaoUpdate(entity=Field.ENTITY_NAME)
	public ActionResult update(
			@Param(value=Field.FIELD_ID, required=true,	desc="字段ID") Long field_id,
			@Param(value=Field.TITLE, required=false,	desc="标题") String title,
			@Param(value=Field.NAME, required=true,	desc="字段名") String name,
			@Param(value=Field.DATA_TYPE, required=false,	desc="数据类型") String data_type,
			@Param(value=Field.DISPLAY_TYPE, required=false,	desc="显示类型") String display_type,
			
			@Param(value=Field.ORDER_INDEX, required=false,	desc="字段顺序") Integer order_index,
			@Param(value=Field.IS_COLUMN, required=false,	desc="网格列") Integer is_column,
			@Param(value=Field.IS_FIELD, required=false,	desc="表单字段") Integer is_field,
			@Param(value=Field.READONLY, required=false,	desc="是否只读") Integer readonly,
			@Param(value=Field.CONDITION, required=false,	desc="是否条件") Integer query_condition,
			
			@Param(value=Field.DS_MODULE_ID, required=false,	desc="配置代码") String ds_config_category,
			@Param(value=Field.DS_SERVICE_ID, required=false,	desc="数据源服务ID") String ds_service_id,
			@Param(value=Field.DS_URL, required=false,	desc="数据源URL") String ds_url,
			@Param(value=Field.TEXT_FIELD, required=false,	desc="显示字段") String text_field,
			@Param(value=Field.VALUE_FIELD, required=false,	desc="值字段") String value_field,
			
			@Param(value=Field.IS_REQUIRED, required=false,	desc="是否必需") Integer is_required,
			@Param(value=Field.MAX_LENGTH, required=false,	desc="最大长度") Integer max_length,
			@Param(value=Field.MIN_VALUE, required=false,	desc="最小值") String min_value,
			@Param(value=Field.MAX_VALUE, required=false,	desc="最大值") String max_value,
			@Param(value=Field.DATA_FORMAT, required=false,	desc="数据格式") String data_format,
			
			@Param(value=Field.REMARKS, required=false,	desc="说明") String remarks,
			@Param(value=Field.STYLE, required=false,	desc="显示样式") String style
			
		) throws Exception {
		return ModelFactory.create(ActionResult.class, 
				Field.IS_COLUMN, is_column == null?1: is_column, 
				Field.IS_FIELD, is_field == null?1: is_field, 
				Field.READONLY, readonly == null?0: readonly
			);
	}

	@MethodInfo("删除")
	@DaoRemove(entity=Field.ENTITY_NAME)
	public ActionResult remove(
			@Param(value=Field.FIELD_ID, required=true,	desc="字段ID") Long field_id
		) throws Exception {
		return null;
	}

	@MethodInfo("删除")
	@DaoRemove(entity=Field.ENTITY_NAME)
	public ActionResult removeByFormId(
			@Param(value=Field.FORM_ID, required=true,	desc="表单ID") Long form_id
		) throws Exception {
		return null;
	}

	@MethodInfo("搜索")
	@DaoQuery(entity=Field.ENTITY_NAME, pageable=true, modelClass=Field.class, osql="order by order_index")
	public QueryResult<Field> findAll(
			@Param(value=Field.FORM_ID, required=true,	desc="表单ID") Long form_id,
			@Param(value=Field.IS_COLUMN, required=false,	desc="网格列") Integer is_column,
			@Param(value=Field.IS_FIELD, required=false,	desc="表单字段") Integer is_field,
			@Param(value=Codes.PAGE_NUM, 	required=false, desc="分页页号，默认0") int page,
			@Param(value=Codes.PAGE_SIZE, 	required=false, desc="分页大小，默认10") int rows) throws Exception {
		return null;
	}

	@MethodInfo("搜索")
	@DaoQuery(entity=Field.ENTITY_NAME, pageable=false, modelClass=Field.class, osql="order by order_index")
	public QueryResult<Field> findByFormId(
			@Param(value=Field.FORM_ID, required=true,	desc="表单ID") Long form_id) throws Exception {
		return null;
	}

	@MethodInfo("查询")
	@DaoQuery(entity=Field.ENTITY_NAME, single=true, throwsNotFoundException=true )
	public Field findById(
			@Param(value=Field.FIELD_ID, required=true,	desc="字段ID") Long field_id
		) throws Exception {
		return null;
	}

}